const initialState = {
    columns: [],
    comment: [],
    refresh: false
};

export const actionsTypes = {
    GET_COLUMNS: "GET_COLUMNS",
    RESPONSE_COLUMNS: "RESPONSE_COLUMNS",

    SUBMIT_COMMENT: "SUBMIT_COMMENT",

    GET_COMMENT: "GET_COMMENT",
    RESPONSE_COMMENT: "RESPONSE_COMMENT",

    CHANGE_REFRESH: "CHANGE_REFRESH"
};

export const actions = {
    get_columns: function () {
        return {
            type: actionsTypes.GET_COLUMNS
        }
    },
    submit_comment: function (data, project_id) {
        return {
            type: actionsTypes.SUBMIT_COMMENT,
            data,
            project_id
        }
    },
    get_comment: function(project_id, role) {
        return {
            type: actionsTypes.GET_COMMENT,
            project_id,
            role
        }
    },
    change_refresh: function(status) {
        return {
            type: actionsTypes.CHANGE_REFRESH,
            status
        }
    }
}

export function reducer(state=initialState, action) {
    switch (action.type) {
        case actionsTypes.RESPONSE_COLUMNS:
            return {
                ...state,
                columns: action.data
            }   
        case actionsTypes.RESPONSE_COMMENT:
            return {
                ...state,
                comment: action.data
            }   
        case actionsTypes.CHANGE_REFRESH:
            return {
                ...state,
                refresh: action.data
            }
        default:
            return state
    }
}